package com.ycw.cs.service.hospital.config;


import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

@Configuration
public class SwaggerConfig {

    @Bean
    public Docket docket(){
        //1.0创建Docket对象
        Docket docket=new Docket(DocumentationType.SWAGGER_2);
        //2.0创建API信息,接口文档的总体描述
        ApiInfo apiInfo=new ApiInfoBuilder()
                .title("前后台分离项目")//设置主题
                .version("1.0")//设置版本
                .description("SpringCloud+Vue+分布式前后台分离项目")//设置接口文档的描述
                .contact(new Contact("落枫",
                        "https://www.baidu.com",
                        "1232321234@qq.com"))//设置作者信息
                .license("Apache 2.0")//设置协议
                .build();
        //3.0设置使用ApiInfo
        docket = docket.apiInfo(apiInfo);
        //4.0设置是否开启swagger
        docket = docket.enable(true);
        //5.0设置参与接口文档生成的包
       /* RequestHandlerSelectors:配置要扫描接口的方式
        basePackage:指定要扫描的包
        any:扫描全部
        none:不扫描
        withClassAnnotation:扫描类上的注解,比如:扫描类上有注解RestController的类
           RequestHandlerSelectors.withClassAnnotation(RestController.class)
        withMethodAnnotation:扫描方法上的注解,比如:扫描方法上有注解GetMapping的请求
           RequestHandlerSelectors.withMethodAnnotation(GetMapping.class)*/
        docket = docket.select().apis(
                RequestHandlerSelectors.basePackage("com.ycw.cs.service.hospital.controller"))
                //.paths() 配置要过滤的路径
                .build();
        return docket;
    }
}
